<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
include_once('../config/field.php');
$ColumnType = 0; //栏目类型:0栏目内容分类,1新闻分类,2产品分类
$page_field = $customize_field['page']; //自定义字段
if(!is_array($page_field)) $page_field = array();
if($_POST['Action']=='Add'){
	$ConfigArticleClick == 1 ? $ArticleClick = $_POST['ArticleClick'] : $ArticleClick = 0;
	$ConfigArticleSort == 1 ? $ArticleSort = $_POST['ArticleSort'] : $ArticleSort = 0;
	unset($ConfigArticleClick,$ConfigArticleSort);
	$npics = picstreatment(0,'ArticleImg');
	$nxURL = $upURL1;
	
	$sql_add1 = $sql_add2 = NULL;
	foreach($page_field as $i => &$n){
		$sql_add1 .= ",`{$n[0]}`";
		if($n[2] != 'IMGVARCHAR'){
			$sql_add2 .= ",'" . trim($_POST[$n[0]]) . "'"; 
		} else {
			//上传类
			$oeURL = $upURL1 = NULL;
			picstreatment(0,$n[0]);
			$oeURL = $upURL1;
			$sql_add2 .= ",'" . $oeURL . "'"; 			
		}
	}
	
	$SQL = "INSERT INTO `" . $dbprefix . "article`(`ArticleLang`,`ArticleRela`,`ArticleTitle`,`ArticleImg`,`ArticleKeyWord`,`ArticleContent`,`ArticleSource`,`ArticlePublished`,`ArticleAudit`,`ArticleRecommended`,`ArticleClick`,`ArticleSort`,`ArticleTime`{$sql_add1}) ";
	$SQL .= "VALUES('" . $Lang . "','" . $_POST['ColumnRela'] . "','" . $_POST['ArticleTitle'] . "','". $nxURL ."','" . $_POST['ArticleKeyWord'] . "','" . $_POST['ArticleContent'] . "',";
	$SQL .= "'{$_POST['ArticleSource']}','{$_POST['ArticlePublished']}','{$_POST['ArticleAudit']}','{$_POST['ArticleRecommended']}','" . $ArticleClick . "', '" . $ArticleSort . "', NOW(){$sql_add2});";
	
	if($ID = $db->ExecuteSQL($SQL,1)){
		AdminLog(2,$Lang,'添加文章内容，结果：操作成功！'); 
		if($npics !== true){
			MsgBox (1,"内容添加成功，图片上传失败，返回信息：{$npics}","PageUpDate.php?Lang={$Lang}&ID={$ID}");
		}
		if($_POST['isHTML'] == 'yes'){
			MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexPage&StartID={$ID}&EndID={$ID}");
		}		
		MsgBox (1,'栏目内容添加成功！','PageManage.php?Lang=' . $Lang);
	} else {
		AdminLog(2,$Lang,'添加文章内容，结果：操作失败！'); 
		MsgBox (1,'操作失败，请检查您提交的数据是否正确！','-1');
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../tools/ckeditor/ckeditor.js" type="text/javascript"></script>
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script src="../js/jquery.js" type="text/javascript"></script>
<script language="javascript">
function trim(str) {
	return str.replace(/(^[\s\u3000]*)|([\s\u3000]*$)/g,"");
}
function FormCheck(){
	if(trim(document.form1.ColumnRela.value)==""){
		alert('请选择所属栏目！');
		document.form1.ColumnRela.focus();
		return false;
	}
	if(trim(document.form1.ArticleTitle.value)==""){
		alert('请填写内容标题！');
		document.form1.ArticleTitle.focus();
		return false;
	}
	<?php if($ConfigArticleClick==1){?>
	if(document.form1.ArticleClick.value.match(/^[0-9]\d*$/)==null){ 
		alert("点击数必须为数字！"); 
		document.form1.ArticleClick.focus(); 
		return false; 
	}
	<?php } if($ConfigArticleSort==1){?>
	if(document.form1.ArticleSort.value.match(/^[0-9]\d*$/)==null){ 
		alert("排序字段必须为数字！"); 
		document.form1.ArticleSort.focus(); 
		return false; 
	}	
	<?php }?>
}
$(document).ready(function(){CKEDITOR.replace('ArticleContent');});
</script>
</head>
<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
	<td><?php TopLang();?></td>
	<td align="right">
		<input type="button" value="内容管理" onClick="javascript:location.href='PageManage.php?Lang=<?php echo $Lang?>'">		
		<input type="button" value="栏目管理" onClick="javascript:location.href='PageColumnManage.php?Lang=<?php echo $Lang?>'">
	</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
<form action="PageAdd.php?Lang=<?php echo $Lang?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return FormCheck()">
  <tr>
    <td colspan="3" align="center" class="Main_Title">添加栏目内容<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td align="right">选择栏目：</td>
<td>
<select name="ColumnRela" id="ColumnRela">
<option selected="selected" value="">==请选择栏目==</option>
<?php
$Rs = $db->SelectSQL("SELECT `ID`,`ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnTime`,`ColumnSort` FROM `" . $dbprefix . "column` WHERE ColumnType = $ColumnType && ColumnLang = $Lang;",2);
@$Rs = sdb::column_sort($Rs);
for ($i=0;$i<count($Rs);$i++ ) {
	Html($Rs[$i]);
	for ($x=1;$x<$Rs[$i][3];$x++){$Spaces .= '├┈┈';} //加与栏目级数相同的空格
	$Rs[$i][3] > 1 ? $Spaces = $Spaces . $Rs[$i][2] : $Spaces = $Rs[$i][2]; //一级栏目前不加空格符
	echo '<option value="' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	unset($Spaces);
}
unset($Rs,$i,$x);
?>  		
</select>
<span class="red">*</span></td>
    <td><a href="PageColumnManage.php"><font color="#0000FF">点击添加栏目</font></a></td>
  </tr>
  <tr class="odd">
    <td align="right">内容标题：</td>
    <td><input name="ArticleTitle" type="text" class="input2" id="ArticleTitle" maxlength="100" />
    <span class="red">*</span></td>
    <td>&nbsp;</td>
  </tr>
<?php if($ConfigArticleImg==1){?>
  <tr class="odd">
    <td align="right">相关图片：</td>
    <td><input name="ArticleImg" type="file" id="ArticleImg" size="35" /></td>
    <td>图片上传大小限制：<font class="Igreen"><?php echo $ps['upload']['max_pics_size'];?></font> KB</td>
  </tr>
<?php } ?>
  <tr class="odd">
  	<td align="right">内容来源：</td>
  	<td><input name="ArticleSource" type="text" class="input2" id="ArticleSource" maxlength="30" /></td>
  	<td>&nbsp;</td>
  	</tr>
<?php
//自定义字段
foreach ($page_field as $i => &$n){
	if($n[2] == 'IMGVARCHAR'){
		$input = "<input name=\"{$n[0]}\" type=\"file\" size=\"35\" />";
		$n[2] = 'VARCHAR';
	} elseif($n[2] == 'TEXT' || $n[2] == 'MEDIUMTEXT' || $n[2] == 'LONGTEXT'){
		$input = "<textarea name=\"{$n[0]}\" style=\"width:300px; height:120px;\"></textarea>";	
	} else {
		$input = "<input name=\"{$n[0]}\" type=\"text\" class=\"input2\" maxlength=\"50\" />";
	}
	echo "<tr class=\"odd\">
    <td align=\"right\">{$n[1]}：</td>
    <td>{$input}</td>
    <td>自定义字段（类型：{$n[2]}）</td>
	</tr>";
}
//End
?> 
  <tr class="odd">
  	<td align="right">关 键 词：</td>
  	<td><input name="ArticleKeyWord" type="text" class="input2" id="ArticleKeyWord" /></td>
  	<td>将被用来作为SEO优化关键词及Tag关键词，用英文逗号隔开，<br />留空时将采用"网站基本设置"中的搜索关键字作为SEO关键词</td>
  	</tr>
  <tr class="odd">
    <td align="right">详细内容：</td>
    <td colspan="2"><textarea id="ArticleContent" name="ArticleContent" rows="10" cols="80"></textarea></td>
</tr>
  <tr class="odd">
  	<td align="right">发 布 人：</td>
  	<td><input name="ArticlePublished" type="text" class="input2" value="<?php echo $_SESSION['UserName']?>" id="ArticlePublished" maxlength="30" /></td>
  	<td>&nbsp;</td>
  	</tr>
  <tr class="odd">
  	<td align="right">通过审核：</td>
  	<td><input name="ArticleAudit" type="radio" id="radio" value="1" checked="checked" />
  		是
  		<input type="radio" name="ArticleAudit" id="radio2" value="0" />
  		否</td>
  	<td>未通过审核的内容将不在任何页面中显示</td>
  	</tr>
  <tr class="odd">
  	<td align="right">是否推荐：</td>
  	<td><input type="radio" name="ArticleRecommended" id="radio3" value="1" />
  		是
  		<input name="ArticleRecommended" type="radio" id="radio4" value="0" checked="checked" />
  		否</td>
  	<td>&nbsp;</td>
  	</tr>
<?php if($ConfigArticleClick==1){?>	
  <tr class="odd">
    <td align="right">点击次数：</td>
    <td><input name="ArticleClick" type="text" id="ArticleClick" value="<?php echo rand(0,500);?>" size="6" maxlength="6" />
      <span class="red">*</span></td>
    <td>不建议修改</td>
  </tr>
<?php } if($ConfigArticleSort==1){?>  
  <tr class="odd">
    <td align="right">排&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;序：</td>
    <td><input name="ArticleSort" type="text" id="ArticleSort" value="0" size="6" maxlength="6" />
      <span class="red">*</span></td>
    <td>值越大越靠前</td>
  </tr>
<?php }?>  
  <tr class="odd">
    <td align="right">发布时间：</td>
    <td><input name="ArticleTime" type="text" disabled="disabled" id="ArticleTime" value="<?php echo gmdate("Y-m-d H:i:s",time()+8*3600)?>" readonly="true" /></td>
    <td>&nbsp;</td>
  </tr>
<?php if($WebStaticHTML == 1){?>
  <tr class="odd">
  	<td align="right">生成静态：</td>
  	<td><input name="isHTML" type="checkbox" id="isHTML" value="yes" />生成HTML</td>
  	<td>添加后将同时生成与该内容相关的所有静态文件</td>
  	</tr>
<?php }?>	  
  <tr class="odd">
    <td align="right"><input name="Action" type="hidden" id="Action" value="Add" /></td>
    <td><input type="submit" name="button" id="button" value="提 交" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="reset" name="button2" id="button2" value="重 置" class="submit" />
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      <input type="button" name="xback" value="返 回" class="submit" onclick="history.back(-1)"></td>
    <td>&nbsp;</td>
  </tr>
  </form>
  </table>
 <table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
</td>
	</tr>
</table>   
</body>
</html>